1. /* sdflog1x.cpp by K.Tsuru */
  2. // function ID 3403
  3. /***********************************************************************
  4. SDouble class
  5. It provides the natulal logalithm by the series
  6. calculate log(1-x) = -x(1 + x/2 + x^2/3 +....) = Log1_X(x),
  7. where |x| must be much less than one(|x|<1.0/DRADIX) and 'x' can be negative.
  8. It is better to use the series
  9. log(1-x) = -(x + x^2/2 + x^3/3 +....)
  10. for the precision.
  11. ************************************************************************/
  12. #ifndef SN_H
  13. #include "sn.h"
  14. #endif
  15. static const char* const func = "Log1_X";
  16. SDouble Log1_X(const SDouble& x){
  17. SDouble sum(x), xn(x*x), delta;
  18. if(x.NetRdxExp() >= 0) x.SetError(x.OUT_OF_RANGE, func, 3403);
  19. sum.FixedPoint(sum.RdxExp());
  20. ulong k = 2, mt = x.SlOpMaxValue();
  21. do{
  22. delta = DsDiv(xn, k);
  23. if(delta.Sign(3403) == 0) break;
  24. sum += delta;
  25. xn *= x;
  26. if( (k++) >= mt ){
  27. sum.SetError(sum.NOT_CONVERGE, func, -3403);
  28. break;
  29. }
  30. }while(xn.Sign(3403));
  31. sum.PointFree();
  32. sum.Reform(3403);
  33. x.upToTerm = k;
  34. sum.ChangeSign();
  35. return sum;
  36. }

sdflog1x.cpp : last modifiled at 2015/12/03 21:42:16(1,097 bytes)
created at 2017/10/07 10:22:50
The creation time of this html file is 2017/10/07 11:29:39 (Sat Oct 07 11:29:39 2017).